package com.shopping.mall.core.module.language.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shopping.mall.base.http.Result;
import com.shopping.mall.core.module.language.entity.Language;
import com.shopping.mall.core.module.language.service.LanguageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "语言管理")
@RestController
@RequestMapping("/language")
public class LanguageController {
    @Autowired
    private LanguageService languageService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<IPage<Language>> getLanguagePage(
        @RequestParam(name = "current", defaultValue = "1") Integer current,
        @RequestParam(name = "size", defaultValue = "10") Integer size,
        Language language) {
        IPage<Language> languagePage=languageService.getLanguagePage(current,size,language);
        return Result.OK(languagePage);
    }

    @ApiOperation("修改")
    @PutMapping
    public Result<Language> update(@Validated(Language.update.class) @RequestBody Language language) {
        languageService.updateById(language);
        return Result.OK();
    }

    @ApiOperation("新增")
    @PostMapping
    public Result<Object> add(@RequestParam String a,@Validated(Language.insert.class) @RequestBody Language language) {
        System.out.println(a);
        System.out.println(language);
        //        languageService.save(language);
        return Result.OK();
    }

    @ApiOperation("通过id查询")
    @GetMapping("/id")
    public Result<Language> getById(@RequestParam String id){
        Language language=languageService.getById(id);
        return Result.OK(language);
    }

    @ApiOperation("查询所有")
    @GetMapping
    public Result<List<Language>> getAll(Language language){
        List<Language> languageList=languageService.getAll(language);
        return Result.OK(languageList);
    }

    @ApiOperation("通过id删除")
    @DeleteMapping("/id")
    public Result<Object> deleteById(@RequestParam String id){
        return languageService.deleteById(id);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public Result<Object> batchDelete(@RequestParam List<String> ids){
        return languageService.batchDelete(ids);
    }
}
